package com.zzxy.spring4.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspectJ {
    @Pointcut("execution(* com.zzxy.spring4.service.impl.*.*(..))")
    public void myPointcut(){}

    @Before("myPointcut()")
   public void myBefore(JoinPoint JoinPoint){
       System.out.println("before method : " + JoinPoint.getSignature().getName());
       System.out.println("my before ...");
   }
   @After("myPointcut()")
   public void myAfter(JoinPoint JoinPoint){
//       System.out.println("after method :" + JoinPoint.getSignature().getName());
       System.out.println("my after ...");

   }
   @Around("myPointcut()")
   public Object myAround(ProceedingJoinPoint pjp) throws Throwable {
       System.out.println("before around :");
       Object obj = pjp.proceed();
       System.out.println("after around :");
       return obj;
   }
   @AfterReturning(value = "myPointcut()",returning = "ret")
   public void myAfterReturning(JoinPoint JoinPoint,Object ret){
       System.out.println("after returning method : " + JoinPoint.getSignature().getName() +"return :" + ret);
   }
   @AfterThrowing(value = "myPointcut()",throwing = "e")
   public void myThrowing(JoinPoint JoinPoint,Throwable e){
       System.out.println("my throwing" + e.getMessage());
   }
}
